home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / Asm / Demos / RainingBobs.s < prev    next >
Encoding:
Text File  |  1997-05-02  |  7.7 KB  |  320 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Raining BOB's Demo
  3. ;------------------
  4. ;This is a demonstration of raining bobs, which I use as a test routine to
  5. ;see how fast some of my blitter routines are.  It's a good example of using
  6. ;MBOB's, try out different MAX_IMAGES values to see how many you can get on
  7. ;screen.  **120** 16 colour 16x8 bobs just manage to run at full speed on my
  8. ;A1200+FAST, change the value if you have a faster machine (600 can be very
  9. ;interesting :-).
  10. ;
  11. ;Technical notes
  12. ;---------------
  13. ;This demo takes direct advantage of some special GMS blitting features,
  14. ;such as restorelist clearing without masks (gain: 10%), and 16 pixel
  15. ;alignment (gain: 15%).  That allows us to have 25% more BOB's on screen!
  16. ;
  17. ;The fact that GMS will use the CPU to draw and clear images when the blitter
  18. ;is busy gives a boost of about 20%+ on an '020, so the overall advantage
  19. ;over a bog standard blitting function (eg BltBitmap()) is at least 40%.
  20. ;Given that such a function would have to be called 120 times with newly
  21. ;calculated parameters each time to draw, and 120 times to do the clears, we
  22. ;are probably looking at least 65% faster... is that good enough?
  23.  
  24.     INCDIR    "INCLUDES:"
  25.     INCLUDE    "games/games_lib.i"
  26.     INCLUDE    "games/games.i"
  27.  
  28. CALL    MACRO
  29.     jsr    _LVO\1(a6)
  30.     ENDM
  31.  
  32. MAX_IMAGES =    120
  33.  
  34.     SECTION    "RainingBOBs",CODE
  35.  
  36. ;===========================================================================;
  37. ;                             INITIALISE DEMO
  38. ;===========================================================================;
  39.  
  40.     STARTGMS
  41.  
  42. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  43.     move.l    GMSBase(pc),a6
  44.     CALL    AllocBlitter
  45.     tst.l    d0
  46.     bne.s    .Error_Blitter
  47.  
  48.     lea    TAGS_BobsPicture(pc),a1
  49.     CALL    LoadPic
  50.     tst.l    d0
  51.     beq.s    .Error_Picture
  52.  
  53.     move.l    PIC_Bobs(pc),a1
  54.     move.w    PIC_Planes(a1),GPlanes+2
  55.     move.l    PIC_Palette(a1),GPalette
  56.  
  57.     lea    TAGS_Screen(pc),a0
  58.     CALL    AddScreen
  59.     tst.l    d0
  60.     beq.s    .Error_Screen
  61.  
  62.     moveq    #2,d0    ;d0 = 2 buffers.
  63.     move.l    #MAX_IMAGES,d1    ;d1 = Maximum amount of images.
  64.     CALL    InitRestore
  65.     move.l    d0,Restorelist
  66.     beq.s    .Error_Restorelist
  67.  
  68.     move.l    Screen(pc),a0
  69.     lea    TAGS_RainBob(pc),a1    ;Initialise the BOB.
  70.     CALL    InitBOB
  71.     tst.l    d0
  72.     beq.s    .Error_RainBob
  73.  
  74.     CALL    ShowScreen
  75.  
  76.     bsr.s    Main
  77.  
  78. .ReturnToDOS
  79.     move.l    GMSBase(pc),a6
  80.     move.l    MBOB_Rain(pc),a1
  81.     CALL    FreeBOB
  82. .Error_RainBob
  83.     move.l    Restorelist(pc),d0
  84.     CALL    FreeRestore
  85. .Error_Restorelist
  86.     move.l    Screen(pc),a0
  87.     CALL    DeleteScreen
  88. .Error_Screen
  89.     move.l    PIC_Bobs(pc),a1
  90.     CALL    FreePic
  91. .Error_Picture
  92.     CALL    FreeBlitter
  93. .Error_Blitter
  94.     MOVEM.L    (SP)+,A0-A6/D1-D7
  95.     moveq    #ERR_OK,d0
  96.     rts
  97.  
  98. ;===========================================================================;
  99. ;                                DEMO CODE
  100. ;===========================================================================;
  101.  
  102. Main:    move.l    GMSBase(pc),a6    ;a6 = GMSBase.
  103.     moveq    #$00,d7
  104.     move.l    MBOB_Rain(pc),a1
  105.  
  106.     move.l    Screen(pc),a0    ;a0 = GameScreen.
  107.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  108.     move.w    MB_AmtEntries(a1),d2
  109.     subq.w    #1,d2
  110. .create    bsr    Regenerate_BOB
  111.  
  112.     move.w    GS_ScrHeight(a0),d1
  113.     CALL    FastRandom
  114.     move.w    d0,BE_YCoord(a2)
  115.  
  116.     lea    NBE_SIZEOF(a2),a2
  117.     dbra    d2,.create
  118.  
  119. ;---------------------------------------------------------------------------;
  120.  
  121. Loop:    addq.w    #1,d7
  122.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  123.     move.w    MB_AmtEntries(a1),d2
  124.     subq.w    #1,d2
  125. .update    bsr.s    Update_BOB
  126.     lea    NBE_SIZEOF(a2),a2
  127.     dbra    d2,.update
  128.  
  129.     move.l    Restorelist(pc),a1    ;a1 = Restorelist.
  130.     CALL    Restore
  131.  
  132.     move.l    a1,a2    ;a2 = Restorelist.
  133.     move.l    MBOB_Rain(pc),a1    ;a1 = BOB to draw.
  134.     moveq    #BUFFER2,d0
  135.     CALL    DrawBOB    ;>> = Draw the BOB
  136.     CALL    WaitVBL    ;>> = Wait for VBL.
  137.     CALL    SwapBuffers    ;>> = Swap the buffers.
  138.  
  139.     moveq    #JPORT1,d0    ;d0 = JoyPort2
  140.     moveq    #JT_ZBXY,d1    ;d1 = Bit switch type.
  141.     CALL    ReadJoyPort    ;>> = Go get port status.
  142.     btst    #MB_LMB,d0
  143.     beq.s    Loop
  144.     rts
  145.  
  146. ;===========================================================================;
  147. ;                               UPDATE A BOB
  148. ;===========================================================================;
  149. ;Function: Moves the entity according to its internal settings.
  150. ;Requires: a1 = BOB structure.
  151. ;       a2 = Entry to update.
  152.  
  153. Update_BOB:
  154.     move.w    BE_YCoord(a2),d0    ;d0 = YCoord
  155.     add.w    BE_Speed(a2),d0    ;d0 = (YCoord)+YSpeed
  156.     cmp.w    GS_ScrHeight(a0),d0
  157.     blt.s    .YOkay
  158.     bsr    Regenerate_BOB
  159.     bra.s    .Animate
  160. .YOkay    move.w    d0,BE_YCoord(a2)
  161.  
  162. .Animate
  163.     tst.w    BE_Locked(a2)
  164.     beq.s    .exit
  165.     move.w    d7,d6
  166.     and.w    #%00000011,d6
  167.     bne.s    .exit
  168.     move.w    BE_FChange(a2),d1
  169.     bgt.s    .Positive
  170.  
  171. .Negative
  172.     cmp.w    #1,BE_Set(a2)
  173.     bgt.s    .NBlue
  174.     beq.s    .NGreen
  175. .NRed    add.w    d1,BE_Frame(a2)
  176.     tst    BE_Frame(a2)
  177.     bge.s    .exit
  178.     move.w    #1,BE_FChange(a2)
  179.     clr.w    BE_Frame(a2)
  180.     rts
  181. .NGreen    add.w    d1,BE_Frame(a2)
  182.     cmp.w    #4,BE_Frame(a2)
  183.     bge.s    .done
  184.     move.w    #1,BE_FChange(a2)
  185.     move.w    #4,BE_Frame(a2)
  186.     rts
  187. .NBlue    add.w    d1,BE_Frame(a2)
  188.     cmp.w    #8,BE_Frame(a2)
  189.     bge.s    .done
  190.     move.w    #1,BE_FChange(a2)
  191.     move.w    #8,BE_Frame(a2)
  192. .exit    rts
  193.  
  194. .Positive
  195.     cmp.w    #1,BE_Set(a2)
  196.     bgt.s    .PBlue
  197.     beq.s    .PGreen
  198. .PRed    add.w    d1,BE_Frame(a2)
  199.     cmp.w    #3,BE_Frame(a2)
  200.     ble.s    .done
  201.     move.w    #-1,BE_FChange(a2)
  202.     move.w    #2,BE_Frame(a2)
  203.     rts
  204. .PGreen    add.w    d1,BE_Frame(a2)
  205.     cmp.w    #7,BE_Frame(a2)
  206.     ble.s    .done
  207.     move.w    #-1,BE_FChange(a2)
  208.     move.w    #6,BE_Frame(a2)
  209.     rts
  210. .PBlue    add.w    d1,BE_Frame(a2)
  211.     cmp.w    #11,BE_Frame(a2)
  212.     ble.s    .done
  213.     move.w    #-1,BE_FChange(a2)
  214.     move.w    #10,BE_Frame(a2)
  215. .done    rts
  216.  
  217. ;===========================================================================;
  218. ;                            REGENERATE BOB ENTITY
  219. ;===========================================================================;
  220. ;Function: Regenerates an entity with completely new data.
  221. ;Requires: a2 = Entry to update.
  222.  
  223. Regenerate_BOB:
  224.     move.w    GS_ScrWidth(a0),d1
  225.     CALL    FastRandom
  226.     subq.w    #4,d0
  227.     and.w    #%1111111111111000,d0
  228.     move.w    d0,BE_XCoord(a2)
  229.  
  230.     moveq    #8,d1
  231.     CALL    FastRandom
  232.     addq.w    #2,d0
  233.     move.w    d0,BE_Speed(a2)
  234.  
  235.     moveq    #12,d1
  236.     CALL    FastRandom
  237.     move.w    d0,BE_Frame(a2)
  238.     move.b    .Sets(pc,d0.w),BE_Set+1(a2)
  239.  
  240.     move.w    #-8,BE_YCoord(a2)
  241.     move.w    #1,BE_FChange(a2)
  242.     eor.w    #1,BE_Locked(a2)
  243.     rts
  244.  
  245. .Sets    dc.b    0,0,0,0
  246.     dc.b    1,1,1,1
  247.     dc.b    2,2,2,2
  248.  
  249. ;===========================================================================;
  250. ;                                  DATA
  251. ;===========================================================================;
  252.  
  253. Restorelist:    dc.l  0
  254.  
  255. ;---------------------------------------------------------------------------;
  256.  
  257. TAGS_Screen:    dc.l  TAGS_GAMESCREEN
  258. Screen:        dc.l  0
  259.         dc.l  GSA_Palette
  260. GPalette:    dc.l  0
  261.         dc.l  GSA_Planes
  262. GPlanes:    dc.l  0
  263.         dc.l  GSA_Attrib,DBLBUFFER
  264.         dc.l  TAGEND
  265.  
  266. ;---------------------------------------------------------------------------;
  267.  
  268. TAGS_BobsPicture:
  269.         dc.l  TAGS_PICTURE
  270. PIC_Bobs:    dc.l  0
  271.         dc.l  PCA_Options,VIDEOMEM|GETPALETTE
  272.         dc.l  PCA_File,.file
  273.         dc.l  TAGEND
  274. .file        dc.b  "GMS:demos/data/PIC.Pulse",0
  275.         even
  276.  
  277. ;---------------------------------------------------------------------------;
  278.  
  279.   ;This is a mutated entrylist that we use for the raining bobs.
  280.  
  281.   STRUCTURE    NBE,BE_SIZEOF
  282.     WORD    BE_Speed    ;Speed of this particular bob.
  283.     WORD    BE_Set    ;0 = Red, 1 = Green, 2 = Blue.
  284.     WORD    BE_FChange
  285.     WORD    BE_Locked    ;Is it animated or not.
  286.     LABEL    NBE_SIZEOF
  287.  
  288. TAGS_RainBob:    dc.l  TAGS_MBOB
  289. MBOB_Rain:    dc.l  0
  290.         dc.l  MBA_AmtEntries,MAX_IMAGES
  291.         dc.l  MBA_Framelist,.frames
  292.         dc.l  MBA_Width,8
  293.         dc.l  MBA_Height,8
  294.         dc.l  MBA_EntryList,Images
  295.         dc.l  MBA_Attrib,CLIP|GENMASKS|CLEAR|CLRNOMASK
  296.         dc.l  MBA_PictureTags,TAGS_BobsPicture
  297.         dc.l  MBA_EntrySize,NBE_SIZEOF
  298.         dc.l  TAGEND
  299.  
  300. .frames        dc.w   0,8*0,0,0    ;RED
  301.         dc.w   0,8*1,0,0
  302.         dc.w   0,8*2,0,0
  303.         dc.w   0,8*3,0,0
  304.         dc.w   8,8*0,0,0    ;GREEN
  305.         dc.w   8,8*1,0,0
  306.         dc.w   8,8*2,0,0
  307.         dc.w   8,8*3,0,0
  308.         dc.w  16,8*0,0,0    ;BLUE
  309.         dc.w  16,8*1,0,0
  310.         dc.w  16,8*2,0,0
  311.         dc.w  16,8*3,0,0
  312.         dc.l  -1
  313.  
  314. ;---------------------------------------------------------------------------;
  315.  
  316.     SECTION    Images,BSS
  317.  
  318. Images:    ds.b    NBE_SIZEOF*MAX_IMAGES    ;X/Y/Frame/Speed/Set/FChange/Locked
  319.  
  320.